﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wicresoft.SMS.Gateway.Host;
using System.Collections;
using System.Xml;
using System.Configuration;
using Wicresoft.SMS.Data;
using Wicresoft.SMS.Common;

namespace smsUnitTest
{
    [TestClass]
    public class AppConfigProviderUnitTest
    {
        [TestMethod]
        public void Get_ConnectionString()
        {
            var provider = new AppConfigProvider();
            var a = provider.ConnectionString;
            //var b = ConfigurationManager.ConnectionStrings["smsConnector"].ConnectionString;

            //Assert.AreEqual<string>("Data Source=localhost;Initial Catalog=MvcCarDB;Integrated Security=True", provider.ConnectionString);

        }
        [TestMethod]
        public void Get_ScanSpan()
        {
            //var provider = new AppConfigProvider();

            //Assert.AreEqual<int>(20000, provider.ScanSpan);

        }
        [TestMethod]
        public void MsgSendTest()
        {
            var xy = GlobalFactory.CreateSMSProvider();
            
            var i = xy.SendMsg("13764307708", "hello word");
            var er = i;
            
           
            
        }

        [TestMethod]
        public void QueryTest()
        {
            var outxml = GlobalFactory.CreateSMSProvider();
            var i = outxml.QueryMsgState("201011303978250771011709");
            var er = i;
        }



        [TestMethod]
        public void SQLGetToBeSented()
        {
            testIConnectStringProvider et = new testIConnectStringProvider();
            var er = DataProviderFactory.CreateDataProvider(et);

            IEnumerable<SMSRecord> result = er.GetMsgToBeSended();
            var s = result;

        }

        [TestMethod]
        public void SQLGetSending()
        {
            testIConnectStringProvider et = new testIConnectStringProvider();
            var er = DataProviderFactory.CreateDataProvider(et);

            IEnumerable<SMSRecord> result = er.GetMsgSending();
            var s = result;

        }

        [TestMethod]
        public void SQLSetMsgSendingFailed()
        {
            testIConnectStringProvider et = new testIConnectStringProvider();
            var er = DataProviderFactory.CreateDataProvider(et);
            List<KeyandMessageId> list = new List<KeyandMessageId>();
            KeyandMessageId _list = new KeyandMessageId();
            _list.MsgIdInDbPrimaryKey = 8;
            list.Add(_list);
            _list = new KeyandMessageId();
            _list.MsgIdInDbPrimaryKey = 11;
            list.Add(_list);
            List<Email> result = er.SetMsgSendingFailed(list);
            foreach (var we in result)
            {
                string de = String.Format(we.Content, "fwew");
                var s = de;
            }

        }

        [TestMethod]
        public void SQLSetMsgSendingSeccess()
        {
            testIConnectStringProvider et = new testIConnectStringProvider();
            var er = DataProviderFactory.CreateDataProvider(et);
            List<KeyandMessageId> list = new List<KeyandMessageId>();
            KeyandMessageId _list = new KeyandMessageId();
            _list.MsgIdInDbPrimaryKey = 3;
            _list.MessageId = "1256325698563214";
            list.Add(_list);
            //_list = new KeyandMessageId();
            //_list.MsgIdInDbPrimaryKey = 5;
            //_list.MessageId = "1256325698563214";
            //list.Add(_list);
            List<Email> result = er.SetMsgSendingSuccess(list);
            var s = result;

            //er.SetMsgSendingSuccess(1,"12");

        }

        [TestMethod]
        public void SendEmailTest()
        {
            testIConnectStringProvider et = new testIConnectStringProvider();
            var er = DataProviderFactory.CreateEmailDataProvider(et);
            List<Email> list = new List<Email>();
            Email email = new Email();
            email.To = "evan23@123.com";
            email.Subject = "Test";
            email.Content = "nihao xiao3";
            list.Add(email);
            bool _out = er.SendEmail(list);
            bool __out = _out;
        }

        [TestMethod]
        public void GetUnsendMailsTest()
        {
            testIConnectStringProvider et = new testIConnectStringProvider();
            var er = DataProviderFactory.CreateEmailDataProvider(et);
            //List<Email> list = new List<Email>();
            var list = er.GetUnsendMails();
            var _out = list.ToList<Email>() ;
        }
    }

    public class testIConnectStringProvider : IConnectStringProvider
    {
        public string ConnectionString
        {
            get { return "metadata=res://*/smsORM.csdl|res://*/smsORM.ssdl|res://*/smsORM.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source=.;Initial Catalog=sms;Integrated Security=True\""; }
        }


        public string HRConnectionString
        {
            get { throw new NotImplementedException(); }
        }
    }


}
